package com.dingwei.superiordiary.mvp.presenter;

import com.dingwei.superiordiary.base.MyBaseBean;
import com.dingwei.superiordiary.bean.FailsBean;
import com.dingwei.superiordiary.bean.IntegerLogBean;
import com.dingwei.superiordiary.custom.myCallback;
import com.dingwei.superiordiary.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.base.URLS;
import com.lihao.baselibrary.base.basePresenter;

import org.xutils.http.RequestParams;
import org.xutils.x;

/**
 * Created by lihao on 2017/9/12.
 */

public class SignFragmentPresenter extends basePresenter {

    private Contract.SignFragmentView signFragmentView;

    public SignFragmentPresenter(Contract.SignFragmentView view) {
        super(view);
        this.signFragmentView = view;
    }


    public void sign() {
        RequestParams rp = new RequestParams(URLS.HOST + URLS.SIGN);
        rp.addBodyParameter("sessionid", BaseActivity.value.getToken());
        x.http().post(rp, new myCallback(BaseActivity.context, MyBaseBean.class, rp) {
            @Override
            public void back(MyBaseBean baseBean, String result) {
                showToast(baseBean.message);
                signFragmentView.signSuccess();
            }

            @Override
            public void fail(FailsBean baseBean, String result) {
            }
        });
    }

    public void initData(int page, final boolean isRefresh, boolean isShowDialog) {
        RequestParams rp = new RequestParams(URLS.HOST + URLS.INTEGRAL_LOG);
        rp.addBodyParameter("sessionid", BaseActivity.value.getToken());
        rp.addBodyParameter("page", page+"");
        x.http().post(rp, new myCallback(BaseActivity.context, IntegerLogBean.class,isShowDialog, rp) {
            @Override
            public void back(MyBaseBean baseBean, String result) {
                IntegerLogBean bean = (IntegerLogBean) baseBean;

                if (isRefresh){
                    signFragmentView.onRefresh(bean);
                }else {
                    signFragmentView.onLoadMore(bean);
                }

            }

            @Override
            public void fail(FailsBean baseBean, String result) {
                signFragmentView.onFail();
            }
        });
    }
}
